@extends('admin.layout.layout')
@section('title','用户管理')
@section('con')
<div id="page-wrapper">
    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header">用户列表</h1>
        </div>
        <!-- /.col-lg-12 -->
    </div>
    <!-- /.row -->
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <!-- /.panel-heading -->
             <div class="panel-body"> 
               <div class="dataTable_wrapper"> 
                <div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
                 <div class="row">
                 <form action="{{url('/admin/user/list')}}">
                  <div class="col-sm-6">
                   <div class="dataTables_length" id="dataTables-example_length">
                    <label>显示 
                        <select name="num" aria-controls="dataTables-example" class="form-control input-sm">
                            <option value="10" @if(!empty($list['num']) && $list['num'] == 10 ){ selected } @endif)>10</option>
                            <option value="25" @if(!empty($list['num']) && $list['num'] == 25 ){ selected } @endif)>25</option>
                            <option value="50" @if(!empty($list['num']) && $list['num'] == 50 ){ selected } @endif)>50</option>
                            <option value="100" @if(!empty($list['num']) && $list['num'] == 100 ){ selected } @endif)>100</option>
                        </select> 条</label>
                   </div>
                  </div>
                  <div class="col-sm-6">
                   <div id="dataTables-example_filter" class="dataTables_filter">
                    <label>搜索:<input name="keywords" value="{{ $list['keywords'] or '' }}" type="search" class="form-control input-sm" placeholder="" aria-controls="dataTables-example" /></label>
                    <button class="btn btn-primary" >查询</button>
                   </div>
                  </div>
                 </div>
                </form>
                 <div class="row">
                  <div class="col-sm-12">
                   <table  id="dataTables-example" class="table table-striped table-bordered table-hover dataTable no-footer" role="grid" aria-describedby="dataTables-example_info" > 
                    <thead> 
                        <tr >
                            <th style="text-align:center">用户Id</th>
                            <th style="text-align:center">用户头像</th>
                            <th style="text-align:center">用户名</th>
                            <th style="text-align:center">用户状态</th>
                            <th style="text-align:center">用户积分</th>
                            <th style="text-align:center">用户权限</th>
                            <th style="text-align:center">操作</th>
                        </tr>
                    </thead> 
                    <tbody> 
                    @foreach($users as $k=>$v)
                          <tr class="gradeA" role="row" style="text-align:center">
                              <!-- <div style = 'display:none' class = 'suibian'>{{$k}}</div> -->
                              <td class="sorting_1">{{$v->uid}}</td> 
                              <td><img src="{{asset($v->pic)}}" width="50px"></td> 
                              <td>{{$v->username}}</td> 
                              <td class="center ">
                              <?php 
                                $arr=['未激活','已激活'];
                                echo $arr[$v->ustatus]; 
                              ?>
                              </td> 
                              <td class="center">{{$v->userpoint}}</td> 
                              <td  class="center up"  >                      
                                <?php 
                                  $arr=['拉黑','普通用户','版主','普通管理员','超级管理员'];
                                  echo $arr[$v->userauth]; 
                                ?>
                              </td> 
                              <td class="center">
                                <button class="btn btn-danger btn-sm delete-btn" type='button'>
                                    删除
                                </button>
                                 <a href="/admin/user/edit?uid={{$v->uid}}" class="btn btn-warning btn-sm edit">修改</a>
                                <button class="btn btn-danger btn-sm up-btn" type='button'>
                                    提权
                                </button>
                                <button class="btn btn-danger btn-sm down-btn" type='button'>
                                    降权
                                </button> 
                               
                              </td> 
                          </tr>
                    @endforeach
                         
                    </tbody> 
                   </table>
                  </div>
                 </div>
                 <div class="row">
                    <!-- 分页 -->
                    {!! $users->appends($list)->render() !!}
                 </div>
                </div> 
               </div> 
               <!-- /.table-responsive --> 
               
              </div>
                <!-- /.panel-body -->
            </div>
            <!-- /.panel -->
        </div>
        <!-- /.col-lg-12 -->
    </div>
</div>
@endsection
@section('js')
<script type="text/javascript">
    //绑定删除单击事件
    $('.delete-btn').click(function(){
        var uid=$(this).parents('tr').find('.sorting_1').html();
        var btn=$(this);
        if(confirm('确认删除?')){
          //发送ajax
          $.get('/admin/user/delete',{uid:uid},function(data){
              if(data==1){
                  //删除成功
                  alert('删除成功');
                  btn.parents('tr').remove();
              }else if(data==5){
                alert('您的权限不够...');
              }else{
                //删除失败
                alert('删除失败');
              }
          });
      }
    });

    //绑定提权单击事件
    $('.up-btn').click(function(){
      var uid=$(this).parents('tr').find('.sorting_1').html();
      var btn=$(this);

      var up=$('.up');
      // var arr=['拉黑','普通用户','版主','普通管理员','超级管理员'];
      //发送ajax
      $.get('/admin/user/up',{uid:uid},function(data){
          // eval('var obj= '+data);
          // // console.log(up.html(),arr[obj.userauth]);
          // if(obj.res==1){
          //     //提权成功
          //     // up.html(arr[obj.userauth]);
          // }else{
          //     //提权失败
          //     alert('提权失败');
          // }
          if(data==1){
            //提权成功
            location.reload(true);
          }else if(data==5){
              //提权失败
              alert('您的权限不够...');
          }else{
              //提权失败
              alert('提权失败');
          }
          
          
      });
    });

    //绑定降权单击事件
    $('.down-btn').click(function(){
      var uid=$(this).parents('tr').find('.sorting_1').html();

      //发送ajax
      $.get('/admin/user/down',{uid:uid},function(data){
          if(data==1){
              //降权成功
              location.reload(true);
          }else if(data==5){
              //降权失败
              alert('您的权限不够...');
          }else{
              //降权失败
              alert('降权失败');
          }
      });
    });

    //绑定修改单击事件
    // $('.edit').click(function(){
    //   var uid=$('input[name=uid]').val();
    //   alert(uid);
    //   return false;
    // })
</script>
@endsection
